<template>
  <div class="home">
      <div>
          <h3>state</h3>
          <p>a:{{ $store.state.a }}</p>
          <p>b:{{ $store.state.b }}</p>
      </div>
      <div>
          <h3>getters</h3>
          <p>doubleA:{{ $store.getters.doubleA }}</p>
          <p>doubleA:{{ $store.getters.doubleB }}</p>
          <p>doubleBoth:{{ $store.getters.doubleBoth }}</p>
      </div>
      <div>
          <h3>mutations</h3>
          <p>
              <button @click="$store.commit('addA')">a++</button>
              <button @click="$store.commit('addAN',10)">a+10</button>
          </p>
          <p>
              <button @click="$store.commit('addB')">b++</button>
          </p>
      </div>
      <div>
          <h3>actions</h3>
          <p>
              <button @click="$store.dispatch('addA_Async')">a++</button>
              <button @click="$store.dispatch('addAN_Async',10)">a+10</button>
          </p>
          <p>
              <button @click="$store.dispatch('addB_Async')">b++</button>
          </p>
          <p>
            <button @click="$store.dispatch('addBoth_Async')">a++,b++</button>
          </p>
          <p>
            <button @click="$store.dispatch('test')">test</button>
          </p>
      </div>
  </div>
</template>

<script>
// @ is an alias to /src


// Vue组件中如果使用store实例

// 手搓版  => 麻烦
// state => this.$store.state
// getters => this.$store.getters
// mutations  => 同步方法 this.$store.commit("addAN",10)
// actions  => 异步方法    this.$store.dispatch("addA_Async",10)


export default {
  name: 'HomeView',
  mounted(){
    console.log("home",this);
    console.log("store实例",this.$store);
  }
}
</script>
